package com.winit.common.support.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    //==================== 项目上线消息 start =======================

    @Value("${uplan_exchange}")
    private String uplan_exchange;

    //这个用来product接收uplan的上线消息
    @Bean
    FanoutExchange uplanExchange() {
        return new FanoutExchange(uplan_exchange);
    }

    @Bean
    public Queue uplanQueue() {
        return new Queue("uplan-queue");
    }

    @Bean
    Binding bindingExchangeUPlan(Queue uplanQueue, FanoutExchange uplanExchange) {
        return BindingBuilder.bind(uplanQueue).to(uplanExchange);
    }

    @Value("${matrix_online_exchange}")
    private String matrix_online_exchange;

    //这个用来product内部发送接收上线消息
    @Bean
    FanoutExchange onlineExchange() {
        return new FanoutExchange(matrix_online_exchange);
    }

    @Bean
    public Queue needOnlineQueue() {
        return new Queue("need-online-queue");
    }


    @Bean
    Binding bindingExchangeNeedOnline(Queue needOnlineQueue, FanoutExchange onlineExchange) {
        return BindingBuilder.bind(needOnlineQueue).to(onlineExchange);
    }

    //==================== 项目上线消息 end =======================


    //========================plan消息 reqQueue接收
    @Value("${plan_send_exchange}")
    private String plan_send_exchange;

    @Bean
    TopicExchange planExchange() {
        return new TopicExchange(plan_send_exchange);
    }

    @Bean
    public Queue reqReceiveQueue() {
        return new Queue("req-receive-status-queue");
    }

    @Bean
    Binding bindingExchangePlan(Queue reqReceiveQueue, TopicExchange planExchange) {
        return BindingBuilder.bind(reqReceiveQueue).to(planExchange).with("#-status-queue");
    }


//    =====================req消息 issueQueue接收

    @Value("${req_send_exchange}")
    private String req_send_exchange;
    @Bean
    TopicExchange reqExchange() {
        return new TopicExchange(req_send_exchange);
    }

    @Bean
    public Queue issueReceiveQueue() {
        return new Queue("issue-receive-status-queue");
    }
    @Bean
    Binding bindingExchangeReq(Queue issueReceiveQueue, TopicExchange reqExchange) {
        return BindingBuilder.bind(issueReceiveQueue).to(reqExchange).with("#-status-queue");
    }


//    =======================issue消息  needQueue接收

    @Value("${issue_send_exchange}")
    private String issue_send_exchange;
    @Bean
    TopicExchange issueExchange() {
        return new TopicExchange(issue_send_exchange);
    }

    @Bean
    public Queue needReceiveQueue() {
        return new Queue("need-receive-status-queue");
    }
    @Bean
    Binding bindingExchangeIssue(Queue needReceiveQueue, TopicExchange issueExchange) {
        return BindingBuilder.bind(needReceiveQueue).to(issueExchange).with("#-status-queue");
    }



}
